/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.msk.base.service.goods;

import com.msk.base.domain.BaseGoodsSupplierRel;
import com.msk.base.domain.goods.Goods;
import com.msk.base.mapper.goods.GoodsDao;
import com.msk.base.service.BaseGoodsSupplierRelService;
import com.msk.base.service.GenerateContratctThread;
import com.msk.common.utils.DateUtil;
import com.msk.common.utils.DateUtils;
import com.msk.common.utils.DictUtils;
import com.msk.common.utils.StringUtils;
import com.msk.common.utils.spring.SpringUtils;
import com.msk.sys.service.CrudService;
import com.msk.wlhy.domain.*;
import com.msk.wlhy.service.HtCompanyService;
import com.msk.wlhy.service.HtLogisticsFrameService;
import com.msk.wlhy.service.HtLogisticsOrderDetailService;
import com.msk.wlhy.service.HtLogisticsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
import org.springframework.transaction.support.TransactionSynchronizationManager;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Map;

/**
 * <p>[]</p>
 * <p>作者：lh</p>
 * <p>邮箱：lh@xiangyou.com</p>
 * <p>创建时间： 2018-11-30 </p>
 * <p>类说明：货主信息审核Service </p>
 * <p>修改记录：</p>
 */
@Lazy(false)
@Service
@Transactional(readOnly = true)
public class GoodsService extends CrudService<GoodsDao, Goods> {

	@Autowired
	private GoodsDao goodsDao;
	private HtLogisticsOrderService htLogisticsOrderService;
	private HtLogisticsOrderDetailService htLogisticsOrderDetailService;
	private HtCompanyService htCompanyService;
	@Autowired
	private HtLogisticsFrameService htLogisticsFrameService;
	@Autowired
	private BaseGoodsSupplierRelService baseGoodsSupplierRelService;
	
	public Goods get(String id) {
		return super.get(id);
	}
	
	public List<Goods> findList(Goods goods) {
		return super.findList(goods);
	}
	
	public Goods selectGoodsById(Goods goods){
		return goodsDao.selectGoodsById(goods);
	}
	
//	public Page<Goods> findPage(Page<Goods> page, Goods goods) {
//		User u = UserUtils.getUser();
//		if(u != null && u.getUserIdentity() != null && "2".equalsIgnoreCase(u.getUserIdentity())){
//			//平台给货主发货货主可以看到
//			goods.setUserIdentity("2");
//			goods.setCreateId(goods.getCurrentUser().getId());
//			goods.getSqlMap().put("dsf", BaseService.dataScopeFilter(goods.getCurrentUser(), "o23", "u"));
//		}else{
//			//管理员可以查看所有的数据
//			goods.getSqlMap().put("dsf", BaseService.dataScopeFilter(goods.getCurrentUser(), "o23", "u"));
//		}
//
//		return super.findPage(page, goods);
//	}

//	public Page<Goods> goodsByPageStatisticsReport(Page<Goods> page, Goods goods) {
//		goods.getSqlMap().put("dsf", BaseService.dataScopeFilter(goods.getCurrentUser(), "o23", "u"));
//		goods.setPage(page);
//		page.setList(dao.goodsStatisticsReport(goods));
//		return page;
//	}
	


//	public Page<Goods> findPageForDriver(Page<Goods> page, Goods goods) {
//		return super.findPage(page, goods);
//	}
	
	/**   
	 * @Title: findTypeList   
	 * @Description: TODO(调用查询状态区间方法)   
	 * @param: @param goods
	 * @param: @return   
	 * @author: wuyao      
	 * @return: List<Goods>      
	 * @throws   
	 * @date:   2018-12-15 下午5:34:56  
	 * @Copyright: 2018 
	 */  
	public List<Goods> findListByType(Goods goods){
		return dao.findListByType(goods);
	}
	
	/**   
	 * @Title: findListByTypePage   
	 * @Description: TODO(返回页调用查询状态区间方法)   
	 * @param: @param page
	 * @param: @param goods
	 * @param: @return   
	 * @author: wuyao      
	 * @return: Page<Goods>      
	 * @throws   
	 * @date:   2018-12-15 下午6:00:41  
	 * @Copyright: 2018 
	 */  
//	public Page<Goods> findListByTypePage(Page<Goods> page, Goods goods) {
//		goods.getSqlMap().put("dsf", BaseService.dataScopeFilter(goods.getCurrentUser(), "o23", "u"));
//		goods.setPage(page);
//		page.setList(dao.findListByType(goods));
//		return page;
//	}
	
	/**   
	 * @Title: update   
	 * @Description: TODO(更新数据)   
	 * @param: @param goods   
	 * @author: wuyao      
	 * @return: void      
	 * @throws   
	 * @date:   2018-12-12 下午7:19:16  
	 * @Copyright: 2018 
	 */  
	@Transactional(readOnly = false)
	public String update(Goods goods){
		String message = null;
//		根据审核后的状态判断后续操作，存入合同信息或者重新提交
		switch (goods.getType()) {
		case "3":
			if("1".equals(this.get(goods).getType())){
				
				this.save(goods);
				message = "更新状态成功";
			}else {
				message = "更新状态不成功";
			}
			break ;
		case "5":
			if("4".equals(this.get(goods).getType())){
				
				this.save(goods);
				message = "更新状态成功";
			}else {
				message = "更新状态不成功";
			}
			break ;
		case "6":
			if("4".equals(this.get(goods).getType())){
				
				this.save(goods);
				message = "更新状态成功";
			}else {
				message = "更新状态不成功";
			}
			break ;
		case "7":
			if("5".equals(this.get(goods).getType())|| 
					("8".equals(this.get(goods).getType()))){
				
				this.save(goods);
				message = "更新状态成功";
			}else {
				message = "更新状态不成功";
			}
			break ;
		case "8":
			if("7".equals(this.get(goods).getType())){
				
				this.save(goods);
				message = "更新状态成功";
			}else {
				message = "更新状态不成功";
			}
			break ;
		case "9":
			if(("7".equals(this.get(goods).getType()))|| 
					("8".equals(this.get(goods).getType()))){
				
				this.save(goods);
				message = "更新状态成功";
			}else {
				message = "更新状态不成功";
			}
			break ;
			
			
		case "2":
			if("1".equals(this.get(goods).getType())||
					("9".equals(this.get(goods).getType()))){
//				将信息状态存入数据库
				this.save(goods);
				message = "更新状态成功";
//				将信息存入合同档案中
				
			}else {
				message = "更新状态不成功";
			}
			break;

		default:
			break;
		}
		return message;
		
	}
	
	@Transactional(readOnly = false)
	public void save(Goods goods) {
		super.save(goods);
	}
	
	@Transactional(readOnly = false)
	public void delete(Goods goods) {
		super.delete(goods);
	}
	
	@Transactional(readOnly = false)
	public int deleteIds(String[] ids) {
		int result = 0;
		for (String id : ids) {
			super.delete(new Goods(id));
			result ++;
		}
		return result;
	}
	
	@Transactional(readOnly = false)
	public void createOrder(Goods goods) {
		htLogisticsOrderService = SpringUtils.getBean(HtLogisticsOrderService.class);
		htLogisticsOrderDetailService = SpringUtils.getBean(HtLogisticsOrderDetailService.class);
		htCompanyService = SpringUtils.getBean(HtCompanyService.class);
		
		// 生成合同
		HtLogisticsOrder htLogisticsOrder = new HtLogisticsOrder();
		htLogisticsOrder.setCompany(goods.getCompany());
		htLogisticsOrder.setOffice(goods.getOffice());
		String htCode = DictUtils.getDictLabel("ZYH", "ht_code", "ZYH") + "-";

		String dateStr =  DateUtils.getDate("yyyyMMdd-");
		String orderNo = htLogisticsOrderService.getOrderNo();
		String orderNoStr = "";
		if(null != orderNo){
			orderNo = orderNo.replace(htCode,"");
			//判断今天是否已经有托运单
			if(orderNo.startsWith(dateStr)){
				//有递增+1
				orderNo = orderNo.replace(dateStr,"");
				Integer originalNumberInt = Integer.parseInt(orderNo) + 1;
				orderNoStr = htCode+ dateStr+ String.format("%05d", originalNumberInt);
			}else{
				//没有生成第一单
				orderNoStr = htCode+dateStr + "00001";
			}
		}else{
			//没有生成第一单
			orderNoStr = htCode+dateStr + "00001";
		}

		htLogisticsOrder.setOrderNo(orderNoStr);
		htLogisticsOrder.setCustomer(goods.getContact());
		htLogisticsOrder.setGoodsType(goods.getGoodsType());
		htLogisticsOrder.setGoodsName(goods.getName());
		htLogisticsOrder.setConsigner(goods.getContact());
		htLogisticsOrder.setConsignee(goods.getContact1());
		htLogisticsOrder.setConsignerNumber(goods.getContactNumber());
		htLogisticsOrder.setConsigneeNumber(goods.getContactNumber1());

		//add by wlxiang 20201103
		htLogisticsOrder.setConsignerUser(goods.getContactUser());
		htLogisticsOrder.setConsignerUserTwo(goods.getContactUserTwo());
		htLogisticsOrder.setConsignerNumberTwo(goods.getContactNumberTwo());

		htLogisticsOrder.setConsigneeUser(goods.getContact1User());
		htLogisticsOrder.setConsigneeUserTwo(goods.getContactUser1Two());
		htLogisticsOrder.setConsigneeNumberTwo(goods.getContactNumber1Two());
		//add by wlxiang 20201103 end

		//记录车辆计价单位
		htLogisticsOrder.setPriceWay(goods.getPriceWay());
		htLogisticsOrder.setStartArea(goods.getStartArea());
		htLogisticsOrder.setStartAreaName(goods.getStartAreaName());
		htLogisticsOrder.setEndArea(goods.getEndArea());
		htLogisticsOrder.setEndAreaName(goods.getEndAreaName());
		htLogisticsOrder.setAllGoodWeight(goods.getWeight());


		// 如果税率为空，则默认税率为6%
		if(StringUtils.isEmpty(goods.getTextRate())){
			String textRate = DictUtils.getDictValue("9","textrate_type","9");
			if(StringUtils.isNotBlank(textRate)){
				goods.setTextRate(textRate);
			}else{
				goods.setTextRate("9");
			}

		}
		htLogisticsOrder.setTextRate(goods.getTextRate());
		
		BigDecimal goodsAllPrice;
		BigDecimal goodsPrice;
		String distanceStr = goods.getDistance();
		Double distance = Double.parseDouble(distanceStr);
		String priceType = goods.getPriceType();
		
		// 总价为空的话通过单价计算出总价(报价方式选择单价的时候计算总价)
		if ("2".equalsIgnoreCase(goods.getPriceWay())){
			//整车费用计算 add wlxiang 20210401
			goodsPrice = new BigDecimal(goods.getPrice());
			goodsAllPrice = new BigDecimal(goods.getPrice() * Double.parseDouble(goods.getCarNum())).setScale(8, RoundingMode.DOWN);
			//货运数量
			htLogisticsOrder.setCarNum(goods.getCarNum());
		}else if ("3".equalsIgnoreCase(goods.getPriceWay())){
			//元吨
			if("0".equals(priceType)){
				goodsAllPrice = new BigDecimal(goods.getPrice()*goods.getWeight()).setScale(8, RoundingMode.DOWN);
				goodsPrice = new BigDecimal(goods.getPrice()).setScale(8, RoundingMode.DOWN);
			}else{
				goodsAllPrice = new BigDecimal(goods.getAllPrice());
				goodsPrice = new BigDecimal(goods.getAllPrice()/goods.getWeight()).setScale(8, RoundingMode.DOWN);
			}
		}else{
			//吨公里
			if("0".equals(priceType)){
				goodsAllPrice = new BigDecimal(goods.getPrice()*goods.getWeight()*distance).setScale(8, RoundingMode.DOWN);
				goodsPrice = new BigDecimal(goods.getPrice()).setScale(8, RoundingMode.DOWN);
			}else{
				goodsAllPrice = new BigDecimal(goods.getAllPrice());
				goodsPrice = new BigDecimal(goods.getAllPrice()/goods.getWeight()/distance).setScale(8, RoundingMode.DOWN);
			}
		}

		// 设置合同单价
		htLogisticsOrder.setTransportPrice(String.valueOf(goodsPrice.doubleValue()));
		// 设置含税金额
		htLogisticsOrder.setRevicePrice(String.valueOf(goodsAllPrice.doubleValue()));
		// 计算税额
		//BigDecimal rateMoney = goodsAllPrice.divide(new BigDecimal("100")).multiply(new BigDecimal(goods.getTextRate())).setScale(2, RoundingMode.HALF_UP);
		BigDecimal textRate = new BigDecimal(goods.getTextRate()).divide(new BigDecimal("100"));
		BigDecimal textRateTemp = new BigDecimal("1").add(textRate);
		BigDecimal rateMoney = goodsAllPrice.divide(textRateTemp,8,RoundingMode.HALF_UP).multiply(textRate).setScale(2,RoundingMode.HALF_UP);
		// 设置税额
		htLogisticsOrder.setRateMoney(String.valueOf(rateMoney.doubleValue()));
		// 计算不含税金额
		/*BigDecimal outRateMoney = goodsAllPrice.subtract(rateMoney);*/
		//BigDecimal outRateMoney = goodsAllPrice.multiply(((new BigDecimal("100")).subtract(new BigDecimal(goods.getTextRate()))).divide(new BigDecimal("100"))).setScale(2, RoundingMode.HALF_UP);
		BigDecimal outRateMoney =goodsAllPrice.subtract(rateMoney).setScale(2,RoundingMode.HALF_UP);;
		// 设置不含税金额
		htLogisticsOrder.setOutRateMoney(String.valueOf(outRateMoney.doubleValue()));
		// 设置合同总金额
		htLogisticsOrder.setAllFreight(goodsAllPrice.doubleValue());
		// 得到直接发布系数值
		String dictValue = DictUtils.getDictValue("once_coefficient", "sys_config", "");
		// 计算运输单价
		BigDecimal freight = goodsPrice.multiply(new BigDecimal(dictValue));
		
		
		htLogisticsOrder.setStatus("2");
		htLogisticsOrder.setGoods(goods);
		htLogisticsOrderService.save(htLogisticsOrder);
		
		
		
		// 生成执行订单
		HtLogisticsOrderDetail htLogisticsOrderDetail = new HtLogisticsOrderDetail();

		String htCodeDetail = DictUtils.getDictLabel("TYD", "ht_code", "TYD") + "-";
		htLogisticsOrderDetail.setOriginalNumber(htCodeDetail);
		//获取当前日期
		String originalNumber = htLogisticsOrderDetailService.getOriginalNumber(htLogisticsOrderDetail );
		String originalNumberStr = "";
		if(null != originalNumber){
			originalNumber = originalNumber.replace(htCodeDetail,"");
			//判断今天是否已经有托运单
			if(originalNumber.startsWith(dateStr)){
				//有递增+1
				originalNumber = originalNumber.replace(dateStr,"");
				Integer originalNumberInt = Integer.parseInt(originalNumber) + 1;
				originalNumberStr = htCodeDetail+ dateStr+ String.format("%05d", originalNumberInt);
			}else{
				//没有生成第一单
				originalNumberStr = htCodeDetail+dateStr + "00001";
			}
		}else{
			//没有生成第一单
			originalNumberStr = htCodeDetail+dateStr + "00001";
		}
		htLogisticsOrderDetail.setOriginalNumber(originalNumberStr);
		String publishWay = goods.getPublishWay();
		if ("2".equals(publishWay)) {//定向发布模式
			if (goods.getHtSupplier() != null) {
				String supplierId = goods.getHtSupplier().getId();
				//承运商
				htLogisticsOrderDetail.setSupplier(new HtSupplier(supplierId));
			}
		}


		if (goods.getHtLogisticsFrame() != null) {
			HtLogisticsFrame htLogisticsFrame = htLogisticsFrameService.get(goods.getHtLogisticsFrame().getId());
			if (htLogisticsFrame != null && StringUtils.isNotBlank(htLogisticsFrame.getConsignUser())) {
				//托运人信息
				htLogisticsOrderDetail.setConsignUser(new HtCompanyCustomer(htLogisticsFrame.getConsignUser()));
			}
		}
		htLogisticsOrderDetail.setOrderType("0");//订单类型0执行单1托运单
		htLogisticsOrderDetail.setValidNum(goods.getValidNum()==null? null:goods.getValidNum().toString());
		htLogisticsOrderDetail.setDistance(goods.getDistance());
		htLogisticsOrderDetail.setMeasureUnit(goods.getMeasureUnit());
		htLogisticsOrderDetail.setAttstr05(goods.getMeasureUnit());
		htLogisticsOrderDetail.setGenerateStatus("0");
		htLogisticsOrderDetail.setGoodsStartTime(goods.getPickTime());
		htLogisticsOrderDetail.setGoodsEndTime(goods.getDeliveryTime());
		htLogisticsOrderDetail.setCompany(goods.getCompany());
		htLogisticsOrderDetail.setOffice(goods.getOffice());
		htLogisticsOrderDetail.setOrderId(htLogisticsOrder.getId());
		htLogisticsOrderDetail.setGoodsName(goods.getName());
		htLogisticsOrderDetail.setGoodsWeight(goods.getWeight());
		htLogisticsOrderDetail.setGoodsType(goods.getGoodsType());
		htLogisticsOrderDetail.setConsigner(goods.getContact());
		htLogisticsOrderDetail.setConsignee(goods.getContact1());
		htLogisticsOrderDetail.setConsignerNumber(goods.getContactNumber());
		htLogisticsOrderDetail.setConsigneeNumber(goods.getContactNumber1());
		//add by wlxiang 20201103
		htLogisticsOrderDetail.setConsignerUser(goods.getContactUser());
		htLogisticsOrderDetail.setConsignerUserTwo(goods.getContactUserTwo());
		htLogisticsOrderDetail.setConsignerNumberTwo(goods.getContactNumberTwo());

		htLogisticsOrderDetail.setConsigneeUser(goods.getContact1User());
		htLogisticsOrderDetail.setConsigneeUserTwo(goods.getContactUser1Two());
		htLogisticsOrderDetail.setConsigneeNumberTwo(goods.getContactNumber1Two());
		//add by wlxiang 20201103 end

		
		htLogisticsOrderDetail.setLoadingArea(goods.getStartArea());
		htLogisticsOrderDetail.setLoadingAreaName(goods.getStartAreaName());
		htLogisticsOrderDetail.setLoadingPlace(goods.getStartPlace());
		htLogisticsOrderDetail.setUnloadingArea(goods.getEndArea());
		htLogisticsOrderDetail.setUnloadingAreaName(goods.getEndAreaName());
		htLogisticsOrderDetail.setUnloadingPlace(goods.getEndPlace());
		htLogisticsOrderDetail.setStartCoordinate(goods.getStartCoordinate());
		htLogisticsOrderDetail.setEndCoordinate(goods.getEndCoordinate());
		htLogisticsOrderDetail.setPriceUnit(goods.getPriceUnit());
		
		htLogisticsOrderDetail.setCustomer(goods.getContact());
		htLogisticsOrderDetail.setStatus("1");
		htLogisticsOrderDetail.setAttstr03("1");

		BigDecimal freightLogistics;
		BigDecimal allFreightLogistics;
		// 总价为空的话通过单价计算出总价
		//2020.09.08修改运费金额取承运商报价的金额，不是平台推送价格

		if ("2".equalsIgnoreCase(goods.getPriceWay())){
			//整车费用计算 add wlxiang 20210401
			freightLogistics = new BigDecimal(goods.getPrice());
			allFreightLogistics = new BigDecimal(goods.getPrice() * Double.parseDouble(goods.getCarNum())).setScale(8, RoundingMode.DOWN);
		}else{
			if("0".equals(goods.getPriceType())){
				allFreightLogistics = new BigDecimal(goods.getPrice()*goods.getWeight()*distance).setScale(8, RoundingMode.DOWN);
				freightLogistics = new BigDecimal(goods.getPrice()).setScale(8, RoundingMode.DOWN);
			}else{
				allFreightLogistics = new BigDecimal(goods.getAllPrice()).setScale(8, RoundingMode.DOWN);
				freightLogistics = new BigDecimal(goods.getAllPrice()/goods.getWeight()/distance).setScale(8, RoundingMode.DOWN);
			}
		}

		// 计算税额
		//BigDecimal detailRateMoney = allFreightLogistics.divide(new BigDecimal("100")).multiply(new BigDecimal(goods.getTextRate())).setScale(2, RoundingMode.HALF_DOWN);
		BigDecimal detailRateMoney = allFreightLogistics.divide(textRateTemp,8,RoundingMode.HALF_UP).multiply(textRate).setScale(2,RoundingMode.HALF_UP);

		// 计算不含税金额
		//BigDecimal detailOutRateMoney = allFreightLogistics.multiply(((new BigDecimal("100")).subtract(new BigDecimal(goods.getTextRate()))).divide(new BigDecimal("100"))).setScale(2, RoundingMode.HALF_DOWN);
		BigDecimal detailOutRateMoney =allFreightLogistics.subtract(detailRateMoney).setScale(2,RoundingMode.HALF_UP);


		// 设置运输单价
		htLogisticsOrderDetail.setFreight(freight.setScale(8, RoundingMode.DOWN).doubleValue());
		htLogisticsOrderDetail.setTextRate(goods.getTextRate());
		// 设置合同单价
		htLogisticsOrderDetail.setPrice(goodsPrice.doubleValue());
		// 设置含税金额
		htLogisticsOrderDetail.setRevicePrice(String.valueOf(allFreightLogistics));
		// 设置税额
		htLogisticsOrderDetail.setRateMoney(String.valueOf(rateMoney.setScale(2, RoundingMode.HALF_UP).doubleValue()));
		// 设置不含税金额
		htLogisticsOrderDetail.setOutRateMoney(String.valueOf(outRateMoney.setScale(2, RoundingMode.HALF_UP).doubleValue()));
		
		/*// 设置含税金额
		htLogisticsOrderDetail.setRevicePrice(String.valueOf(goods.getAllPrice()));	
		BigDecimal bg = new BigDecimal(goods.getAllPrice()/100*Double.parseDouble(goods.getTextRate())).setScale(2, RoundingMode.UP);		
		// 设置税额
		htLogisticsOrderDetail.setRateMoney(String.valueOf(bg.doubleValue()));
		BigDecimal bg1 = new BigDecimal(goods.getAllPrice()-bg.doubleValue()).setScale(2, RoundingMode.UP);	
		// 设置不含税金额
		htLogisticsOrderDetail.setOutRateMoney(String.valueOf(bg1.doubleValue()));*/
		
		
		
		if(StringUtils.isNoneEmpty(goods.getGoodsNums())){			
			htLogisticsOrderDetail.setGoodsNumber(Double.parseDouble(goods.getGoodsNums()));
		}
		htLogisticsOrderDetailService.save(htLogisticsOrderDetail);
		//异步执行生成合同线程
		final String id = htLogisticsOrder.getId();
		final String detailId = htLogisticsOrderDetail.getId();
		TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
			// 在事务提交之后执行的代码块（方法）  此处使用TransactionSynchronizationAdapter，其实在Spring5后直接使用接口也很方便了~
			@Override
			public void afterCommit() {

				//异步执行生成合同线程
				GenerateContratctThread generateContratctThread = new GenerateContratctThread(id, detailId);
				generateContratctThread.start();
			}
		});
	}


	/**
	 * 货源编号生成规则、例如：“WLJJD-20200711-002”
	 * @return
	 */
	public synchronized String generateGoodsCode() {
        int num = 0;
		String maxCode = goodsDao.findDateMaxCode(null);
		if (StringUtils.isNotBlank(maxCode)) {
		    String[] codeArr = maxCode.split("-");
		    if (codeArr.length > 1) {
                num = Integer.parseInt(codeArr[1]);
            }
        }
		String serNo = String.format("%03d", num+1);
		String code = "WLJJD-" + DateUtil.nowDatetime() + '-' + serNo;
		return code;
	}


	@Transactional(readOnly = false)
	public void saveNew(Goods goods) {
		super.save(goods);
		String htSuppliers = goods.getHtSuppliers();
		String goodsId = goods.getId();
		if(StringUtils.isNotBlank(htSuppliers)&&htSuppliers.length() > 0 && !StringUtils.isBlank(goodsId)){
			String htSupplierses [] = null;
			if(htSuppliers.contains(";")){
				htSupplierses = htSuppliers.split(";");
			}
			if(htSupplierses != null){
				baseGoodsSupplierRelService.deleteByGoodsId(goodsId);
				for(int i = 0; i < htSupplierses.length;i++){
					if(htSupplierses[i].length() >0 ){
						BaseGoodsSupplierRel baseGoodsSupplierRel = new BaseGoodsSupplierRel();
						baseGoodsSupplierRel.setGoodsId(goodsId);
						baseGoodsSupplierRel.setSupplierId(htSupplierses[i]);
						baseGoodsSupplierRelService.save(baseGoodsSupplierRel);
					}
				}
			}
		}
	}
	

	/**
	 * 根据订单编号查询货源
	 * @param orderNo
	 * @return
	 */
	public Goods selectByOrderNo(String orderNo) {
		return goodsDao.selectByOrderNo(orderNo);
	}

	/**
	 * 根据订单编号更改支付状态
	 * @param goods
	 * @return
	 */
	public int updateByOrderNo(Goods goods) {
		return goodsDao.updateByOrderNo(goods);
	}

	/**
	 * 根据ID更改支付状态
	 * @param goods
	 * @return
	 */
	@Transactional(readOnly = false)
	public int updatePayStatusById(Goods goods) {
		return goodsDao.updatePayStatusById(goods);
	}

	/**
	 * 根据订单编号更改单价和总价
	 * @param goods
	 * @return
	 */
	@Transactional(readOnly = false)
	public int updatePriceByOrderNo(Goods goods) {
		goods.setType("11");
		return goodsDao.updatePriceByOrderNo(goods);
	}

	/**
	 * @Description 货主货源列表
	 * @Author wlxiang
	 * @Date 19:55 2023/6/5
	 * @Param
	 * @param contact
	 * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
	 **/
	public List< Map<String,Object>> selectGoodsListByContact(String contact,String publishWay,String type){
		return goodsDao.selectGoodsListByContact(contact,publishWay,type);
	};

	/**
	 * @author llh
	 * @date 2023/6/16
	 * @return java.util.List<com.msk.base.domain.goods.Goods>
	 * @description 货主签约列表      
	 */
	public List<Map<String,Object>> findSignedList(Goods goods){
		return goodsDao.findSignedList(goods);
	}

	/**
	 * @author llh
	 * @date 2023/8/7 14:11
	 * @param goods
	 * @description 查询货主未签约货源数量
	 * @return int
	 */
	public int getUnsignedCount(Goods goods){
		return goodsDao.findUnsignedCount(goods);
	}
	
	/**
	 * @author llh
	 * @date 2023/6/16
	 * @return com.msk.base.domain.goods.Goods
	 * @description 货主签约详情      
	 */
	public Goods getSignedInfo(Goods goods){
		return goodsDao.getSignedInfo(goods);
	}

	/**
	 * @Description 货源询价列表
	 * @Author wlxiang
	 * @Date 18:20 2023/7/3
	 * @Param
	 * @param supplierUser //司机、承运商ID
	 * @param biddingStatus //竞价状态 0:未竞价 1:竞价中 2:竞价成功 3:竞价失败
	 * @return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
	 **/
	public List<Map<String,Object>> selectSourceInquiryListByContact(String supplierUser, String biddingStatus){
		return goodsDao.selectSourceInquiryListByContact(supplierUser,biddingStatus);
	};
}